package com.omni.monitor.controller;

import com.omni.monitor.model.threadpool.ThreadPoolStats;
import com.omni.monitor.model.threadpool.ThreadPoolTrend;
import com.omni.monitor.model.trace_monitor.Entrance_ServiceInfo;
import com.omni.monitor.model.trace_monitor.TraceLogEsPageRes;
import com.omni.monitor.model.trace_monitor.TraceLogEsReq;
import com.omni.monitor.model.trace_monitor.TraceNode;
import com.omni.monitor.plugin.threadpool.ThreadPoolMonitor;
import com.omni.monitor.plugin.trace_monitor.TraceContext;
import com.omni.monitor.plugin.trace_monitor.TraceService;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/trace-monitor")
public class TraceMonitorController {


    private final TraceService traceService;

    public TraceMonitorController(TraceService traceService) {
        this.traceService = traceService;
    }

    /**
     * 根据traceId获取trace信息
     *
     * @param traceId 唯一号
     * @return 调用链明细
     */
    @GetMapping("/getTraceById")
    public List<TraceNode> getTraceById(@RequestParam("traceId") String traceId) {
        return traceService.getTraceNodeList(traceId);
    }

    /**
     * 设置监控开关
     */
    @GetMapping("/setMonitorEnabled")
    public String setMonitorEnabled(@RequestParam("enableKey") String enableKey,
                                    @RequestParam("enabledValue") String enabledValue) {
        return traceService.setMonitorEnabled(enableKey, enabledValue);
    }
    /**
     * 设置监控开关
     */
    @GetMapping("/getMonitorEnabled")
    public String setMonitorEnabled(@RequestParam("enableKey") String enableKey) {
        return traceService.getMonitorEnabled(enableKey);
    }
    /**
     * 获取所有根节点 方法调用树列表
     *
     * @return 根节点
     */
    @PostMapping("/getRootNodes")
    public TraceLogEsPageRes getRootNodes(@RequestBody TraceLogEsReq req) {

        return traceService.getRootNodes(req);
    }
    /**
     * 获取所有服务信息
     *
     * @return 服务信息
     */
    @GetMapping("/getEntranceServiceInfo")
    public List<Entrance_ServiceInfo> getEntranceServiceInfo() {
        return traceService.getEntranceServiceInfo();
    }
}